import hasRole from './permission/hasRole'
import hasPermi from './permission/hasPermi'
import dialogDrag from './dialog/drag'
import dialogDragWidth from './dialog/dragWidth'
import dialogDragHeight from './dialog/dragHeight'
import clipboard from './module/clipboard'
import num from './num/index'
const install = function (Vue) {
  Vue.directive('hasRole', hasRole)
  Vue.directive('hasPermi', hasPermi)
  Vue.directive('clipboard', clipboard)
  Vue.directive('dialogDrag', dialogDrag)
  Vue.directive('dialogDragWidth', dialogDragWidth)
  Vue.directive('dialogDragHeight', dialogDragHeight)
  Vue.directive('num', num),
    Vue.directive('currency', {
      bind(el, binding, vnode) {
        el.addEventListener('input', function () {

          const input = el.querySelector('.el-input__inner') || el.querySelector('.el-textarea__inner') || el;

          let value = input.value;
          console.log(value)
          // 移除非数字和小数点字符
          value = value.replace(/[^\d.]/g, '');
          // 保留两位小数
          value = parseFloat(value).toFixed(2) || '';
          console.log(value)
          vnode.context[binding.expression] = value; // 更新数据
        });
      }
    });
}

if (window.Vue) {
  window['hasRole'] = hasRole
  window['hasPermi'] = hasPermi
  Vue.use(install); // eslint-disable-line
}


export default install
